package com.example.weather.girl

import androidx.databinding.ViewDataBinding
import com.example.library_base.base.BaseModel
import com.example.library_base.base.adapter.BaseAdapter
import com.example.weather.BR
import com.example.weather.R
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import javax.inject.Inject

@Module
@InstallIn(ViewModelComponent::class)
class GirlAdapter @Inject constructor() : BaseAdapter<GirlModel>(R.layout.item_girl_left) {

    companion object {
        private const val ITEM_TYPE_LEFT = 0x0001
        private const val ITEM_TYPE_RIGHT = 0x0002
    }

    @Inject
    lateinit var eventHandler: GirlEventHandler

    init {
//        mItemViewType = object : ItemViewType<GirlModel>() {
//            override fun getItemType(t: GirlModel): Int {
//                return when {
//                    t.type.equals("left", true) -> {
//                        ITEM_TYPE_LEFT
//                    }
//                    t.type.equals("right", true) -> {
//                        ITEM_TYPE_RIGHT
//                    }
//                    else -> {
//                        -1
//                    }
//                }
//            }
//        }
//
//        mItemViewType?.registerItemType(ITEM_TYPE_LEFT, R.layout.item_girl_left)
//            ?.registerItemType(ITEM_TYPE_RIGHT, R.layout.item_girl_right)
    }

    override fun onBindItem(binding: ViewDataBinding?, bean: GirlModel) {
        binding?.setVariable(BR.girlModel, bean)
        binding?.setVariable(BR.event, eventHandler)
        binding?.executePendingBindings()
    }

    override fun <H : BaseModel> onHeaderBindItem(binding: ViewDataBinding?, bean: H) {
        binding?.setVariable(BR.headerModel, bean)
        binding?.executePendingBindings()
    }

    override fun <H : BaseModel> onFooterBindItem(binding: ViewDataBinding?, bean: H) {
        binding?.setVariable(BR.footerModel, bean)
        binding?.executePendingBindings()
    }
}